<!doctype html>
<html>
<head>
	<meta charset="utf-8">
	<title>注册</title>
 	<link href="check.css" rel="stylesheet" type="text/css">  
	<script type="text/javascript" src="load.js">
	</script>
</head>

<body οnlοad="load_greeting()">
	<table>   
		<tr >
          <td>email:</td>
          <td><input type="email" name="email" id="email" size="20" onChange='check(this.id)'></td>
          <td id="emailCheck" class="check" hidden="true">电子邮件名非法！</td>
        </tr>	  
        <tr>
          <td>密码:</td>
          <td><input type="password" name="apassword" id="apassword" size="20" onChange='check("apassword")'></td>
          <td id="apasswordCheck" class="check" hidden="true">密码长度至少8位</td>
        </tr>
        <tr>
          <td>确认密码:</td>
          <td><input type="password" name="cpassword" id="cpassword" size="20" onChange='check("cpassword")'></td>
          <td id="cpasswordCheck" class="check" hidden="true">两次密码输入不一致</td>
        </tr>
        <tr>
          <td><input type="button" name="codeBtn" id="codeBtn" value="获取验证码" size="20"></td>
        </tr>
		<tr>
		  <td>验证码:</td>
          <td><input type="text" name="code" id="code" size="20"></td>
        </tr>
    </table>
	  
	<form id="registerForm" align="left" action="http://www.localdomain.com/api/user/register/email/pwd/code" method="get">
      <input type="submit" id = "submit">
      <input type="reset" id = "reset">
    </form>
	
	<script>
		
        var btn = document.querySelector("#codeBtn");
		const xhr1 = new XMLHttpRequest();
        btn.onclick = function () {
            let emailValue = document.querySelector("#email").value;
			xhr1.onreadystatechange = function() {
				if(xhr1.readyState == 4) {
					var returnData = xhr1.responseText;
					alert(returnData);
				}
			};
            xhr1.open('get','http://www.localdomain.com/api/code/create/'+emailValue);
            xhr1.send();
        }
		
		 var submitBtn = document.getElementById("submit");
		 submitBtn.onclick = function (event) {
			let emailValue = document.querySelector("#email").value;
			let pwdValue = document.querySelector("#apassword").value;
			let codeValue = document.querySelector("#code").value;
			registerForm.action='/api/user/register/'+emailValue+'/'+pwdValue+'/'+codeValue+''
			return true;
		 };
    </script>
</body>
</html>
